﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Jizsoft.JFrame.Util
{
    public class Md5Util
    {
        public static string ToMd5(string sourceStr)
        {
            MD5 newMd5 = new MD5CryptoServiceProvider();
            byte[] sourceBit = Encoding.Default.GetBytes(sourceStr);
            byte[] directBit = newMd5.ComputeHash(sourceBit);

            return toBitString(directBit);
        }

        static string toBitString(byte[] data)
        {
            StringBuilder builder = new StringBuilder();
            for (int index = 0; index < data.Length; index++)
            {
                builder.AppendFormat("{0:X2}", data[index]);
            }
            return builder.ToString();
        }
    }
}
